package com.wanlian.File;

import com.wanlian.encrypt.HexUtil;
import com.wanlian.netty.File.model.FileHead;

public class NetFileInfo {
    private String fileId;
    private String fileName;
    private String filePath;
    private int fileType;
    private long totalSize;
    private String sizeUnit;
    private long currentIndex;
    private long size;
    private byte[] bytes;
    private boolean bContinue;
    private String hbytes;
    private String mValue;

    public NetFileInfo(){

    }

    public NetFileInfo(FileHead head){
        this.fileName=head.getFileName();
        this.totalSize=head.getTotal();
        this.currentIndex=head.getOffset();
        this.size=head.getSize();
        this.bContinue=this.isbContinue();
    }


    public NetFileInfo cope() {
        NetFileInfo newNetFileInfo = new NetFileInfo();
        newNetFileInfo.fileId = this.fileId;
        newNetFileInfo.fileName = this.fileName;
        newNetFileInfo.filePath = this.filePath;
        newNetFileInfo.totalSize = this.totalSize;
        newNetFileInfo.currentIndex = this.currentIndex;
        newNetFileInfo.sizeUnit = this.sizeUnit;
        newNetFileInfo.size = this.size;
        newNetFileInfo.bytes = this.bytes;
        newNetFileInfo.bContinue = this.bContinue;
        newNetFileInfo.fileType = this.fileType;
        newNetFileInfo.mValue=this.mValue;
        return newNetFileInfo;
    }


    public void appendToLine(NetFileInfo netFileInfo) {
        if (netFileInfo != null) {
            byte[] resArr = new byte[this.bytes.length + netFileInfo.bytes.length];
            System.arraycopy(this.bytes, 0, resArr, 0, this.bytes.length);
            System.arraycopy(netFileInfo.bytes, 0, resArr, this.bytes.length, netFileInfo.bytes.length);
            this.bytes = resArr;
        }
    }

    public boolean checkCanAppendALine(NetFileInfo netFileInfo) {
        if (netFileInfo != null) {
            if (netFileInfo.getCurrentIndex() != this.getCurrentIndex() + this.getSize()) {
                return false;
            } else {
                this.size += netFileInfo.getSize();
            }
        }
        return true;
    }

    public String getFileId() {
        return fileId;
    }

    public void setFileId(String fileId) {
        this.fileId = fileId;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public String getSizeUnit() {
        return sizeUnit;
    }

    public void setSizeUnit(String sizeUnit) {
        this.sizeUnit = sizeUnit;
    }

    public long getCurrentIndex() {
        return currentIndex;
    }

    public void setCurrentIndex(long currentIndex) {
        this.currentIndex = currentIndex;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

    public boolean isbContinue() {
        return bContinue;
    }

    public void setbContinue(boolean bContinue) {
        this.bContinue = bContinue;
    }

    public int getFileType() {
        return fileType;
    }

    public void setFileType(int fileType) {
        this.fileType = fileType;
    }

    public String getHbytes() {
        return hbytes;
    }

    public void setHbytes(String hbytes) {
        this.hbytes = hbytes;
    }

    public void transferToBytes(){
        this.bytes=HexUtil.decode(this.hbytes);
        this.hbytes="";
    }

    public void transferToHBytes(){
        this.hbytes= HexUtil.encode(this.bytes);
        this.bytes=new byte[1];
    }

    public String getmValue() {
        return mValue;
    }

    public void setmValue(String mValue) {
        this.mValue = mValue;
    }
}
